#include <iostream>
#include "SqlTableOp.h"

namespace Media{
    const std::string DbPath = "/nfsroot/";//"/extern/";
    const std::string ScenesDbName = "scenes.db";

    SqlTableOp::Ptr SqlTableOp::Instance(){
        static auto ptr = std::make_shared<SqlTableOp>();
        return ptr;
    }

    SqlTableOp::SqlTableOp(){
        m_dbFullPath = DbPath + ScenesDbName;
        init();
    }
    SqlTableOp::~SqlTableOp()= default;

    bool SqlTableOp::init(){
        if(!createTables()) return false;

        return true;
    }

    bool SqlTableOp::createTables(){
        try{
            m_sqlDriver = std::make_shared<internal::storage_t<InputSourceTableType, OutputSourceTableType,\
                 ItemTableType,ScenesTableType>>(m_dbFullPath, \
                 std::make_tuple(CreateInputSourceTable,CreateOutputSourceTable, \
                 CreateItemTable, CreateScenesTable));
    
            m_sqlDriver->sync_schema();
        }catch(const std::system_error& e){
            std::cout << e.what() << std::endl;
            return false;
        }

        return true;
    }

}